1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.SceneManagement;
5
6 public
class MenuController : MonoBehaviour {
7
8     
public static MenuController instance;
9
10     
[SerializeField]
11     
private GameObject[] birds;
12
13     
private bool isGreenBirdUnlocked, isRedBirdUnlocked;
14
15     
void Awake(){
16         MakeInstance ();
17     }
18
19     
// Use this for initialization
20     
void Start () {
21         birds [GameControllers.instance.GetSelectedBird()].SetActive (
true);
22         CheckIfBirdsAreUnlocked ();
23
24     }
25     
26     
// Update is called once per frame
27     
void MakeInstance () {
28         
if (instance == null) {
29             instance =
this;
30         }
31     }
32
33     
void CheckIfBirdsAreUnlocked(){
34         
if (GameControllers.instance.IsRedBirdUnlocked () == 1) {
35             isRedBirdUnlocked =
true;
36         }
37
38         
if (GameControllers.instance.IsGreenBirdUnlocked () == 1) {
39             isGreenBirdUnlocked =
true;
40         }
41     }
42
43     
public void PlayGame() {
44         SceneManager.LoadScene (
"GamePLayScene");
45     }
46
47     
public void QuitGame() {
48         Application.Quit();
49     }
50
51     
public void ChangeBird() {
52         
if (GameControllers.instance.GetSelectedBird () == 0) {
53             
if (isGreenBirdUnlocked) {
54                 birds [
0].SetActive (false);
55                 GameControllers.instance.SetSelectedBird (
1);
56                 birds [GameControllers.instance.GetSelectedBird ()].SetActive (
true);
57             }
58
59         }
else if(GameControllers.instance.GetSelectedBird() == 1) {
60             
if (isRedBirdUnlocked) {
61                 birds [
1].SetActive (false);
62                 GameControllers.instance.SetSelectedBird (
2);
63                 birds [GameControllers.instance.GetSelectedBird ()].SetActive (
true);
64
65             }
else {
66                 birds [
1].SetActive (false);
67                 GameControllers.instance.SetSelectedBird (
0);
68                 birds [GameControllers.instance.GetSelectedBird ()].SetActive (
true);
69             }
70
71         }
else if(GameControllers.instance.GetSelectedBird() == 2){
72             birds [
2].SetActive (false);
73             GameControllers.instance.SetSelectedBird (
0);
74             birds [GameControllers.instance.GetSelectedBird ()].SetActive (
true);
75         }
76     }
77 }


Gõ tìm kiếm nhanh...